package news.util;

import java.util.List;

/**
 * @Author Gong
 * @Description 分页对象
 * @dATE 2022/2/27 17:10
 **/
public class PageBean<T> {

    private int currPageNo = 1; // 当前页码
    private int pageSize = 10;    // 页面大小，即每页显示记录数
    private int totalCount;          // 记录总数
    private int totalPageCount; // 总页数需要计算

    private int start;//查询起始参数

    List<T> objectList;//集合对象

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getCurrPageNo() {
        return currPageNo;
    }

    public void setCurrPageNo(int currPageNo) {
        this.currPageNo = currPageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        //计算总页数
        initTotalPageCount();
        //结合当前的页码计算start
        initStart();
    }
    /**
     * @Author GongXL
     * @Description  计算总页数
     * @Date 17:20 2022/2/27
     * @Param []
     * @return void
     **/
    private void initTotalPageCount(){
        if (this.totalCount > 0) {
            this.totalPageCount = (this.totalCount % this.pageSize == 0) ?
                    (this.totalCount / this.pageSize) :
                    ((this.totalCount / this.pageSize) + 1);
        }
    }
    /**
     * @Author GongXL
     * @Description  结合当前的页码计算start
     * @Date 17:21 2022/2/27
     * @Param []
     * @return void
     **/
    private void initStart(){
        this.start = (this.currPageNo  -1) * this.pageSize;
    }
    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }

    public List<T> getObjectList() {
        return objectList;
    }

    public void setObjectList(List<T> objectList) {
        this.objectList = objectList;
    }
}
